package com.ym.medical.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.ym.core.shiro.ShiroUtil;
import com.ym.core.utils.tkmybatis.BaseSVImpl;
import com.ym.medical.dao.FeedBackDao;
import com.ym.medical.domain.entity.FeedBackEntity;
import com.ym.medical.domain.param.FeedBackParam;
import com.ym.medical.domain.param.FeedBackQueryParam;
import com.ym.medical.domain.param.FeedBackUpdateParam;
import com.ym.medical.domain.vo.FeedBackListPcVO;
import com.ym.medical.service.IFeedBackSV;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * 帮助反馈Service业务层处理
 *
 * @author ym
 * @date 2020-09-01
 */
@Service
@Transactional(rollbackFor = Exception.class)
public class FeedBackSVImpl extends BaseSVImpl<FeedBackEntity, FeedBackDao> implements IFeedBackSV {

    /**
     * 查询帮助反馈列表
     *
     * @param queryParam 帮助反馈 查询参数
     * @return 帮助反馈
     */
    @Override
    public List<FeedBackListPcVO> selectListPC(FeedBackQueryParam queryParam) {
        List<FeedBackListPcVO> feedBacks = mapper.selectListPC(queryParam);
        return feedBacks;
    }

    /**
     * 新增帮助反馈
     *
     * @param updateParam 帮助反馈 新增参数
     * @return 结果
     */
    @Override
    public Long insertPC(FeedBackUpdateParam updateParam) {
        FeedBackEntity entity = updateParam.covert();
        entity.setUserId(ShiroUtil.getLoginId(true));
        this.insert(entity);
        return entity.getId();
    }

    /**
     * 修改帮助反馈
     *
     * @param updateParam 帮助反馈 修改参数
     * @return 结果
     */
    @Override
    public int updateByIdPC(FeedBackUpdateParam updateParam) {
        FeedBackEntity entity = updateParam.covert();
        entity.setUserId(ShiroUtil.getLoginId(true));
        int result = this.updateById(entity);
        return result;
    }

    /**
     * 反馈列表
     * @param pageNo
     * @param limit
     * @param feedBackModel
     * @return
     */
    @Override
    public PageInfo<FeedBackEntity> feedbackList(int pageNo, int limit, FeedBackParam feedBackModel) {
        PageHelper.startPage(pageNo,limit);
        List<FeedBackEntity> feedBacks =  mapper.feedbackList(feedBackModel);
        return new PageInfo<>(feedBacks);
    }
}
